home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ShareWare OnLine 2
/
ShareWare OnLine Volume 2 (CMS Software)(1993).iso
/
games2
/
namegram.zip
/
NEWPOS.FUN
< prev
next >
Wrap
Text File
|
1993-01-04
|
2KB
|
32 lines
FUNCTION NEW_POS(MyChar : char; VAR Str) :byte;
{----------------------------------------------------------------}
{ The TURBO "Pos" function is more complex than we need -- it }
{ finds the position of a whole STRING within another STRING. }
{ We just need to find one character within a STRING, as fast }
{ as possible. This routine, in 8088 assembler language, is }
{ much faster. Because I'm lazy, I took the easy way out to }
{ give the function its returned value -- I assigned that value }
{ via a GLOBAL variable, "Make_It_Easy". You'll have to either }
{ put that global variable into any program that uses this new }
{ POS function, or rewrite the end of the INLINE code to do it }
{ in a more elegant fashion. }
{----------------------------------------------------------------}
BEGIN
Inline(
$FC/ { CLD ;forward direction}
$8A/$46/<MyChar/{ MOV AL,<MyChar[BP];character into AL}
$C4/$7E/<STR/ { LES DI,<Str[BP] ;load DI using ES }
$31/$C9/ { XOR CX,CX ; clear out CX }
$26/$8A/$0D/ { MOV CL,ES:[DI] ;load length }
$89/$CA/ { MOV DX,CX ;save the length }
$47/ { INC DI }
$F2/$AE/ { REPNE SCASB ;Scan for char }
$75/$02/ { JNZ noChar }
$29/$D1/ { SUB CX,DX ;Take countdown }
{ from original total}
$F7/$D9/ { NEG CX }
{noChar:}
$88/$0E/Make_It_Easy); { Mov [<Make_It_Easy],CX}
New_Pos := Make_It_Easy;
end;